<?php

namespace Analysis\Model;

use Think\Model;

class CashModel extends Model
{
    protected $autoCheckFields = false;
    private $start;
    private $end;
    private $c;

    const LIMIT = 500;

    public function getTime($start, $end, $cod)
    {
        $this->start=$start;
        $this->end=$end;
        $this->c=$cod;
        
        $count = abs(date("Y", $this->end) - date("Y", $this->start)) * 12 + abs(date("m", $this->end) - date("m", $this->start));
        $s_month_last = strtotime(date("Y-m-t", $this->start));
        $e_month_first = strtotime(date("Y-m-1", $this->end));
        $arr = array();
        for ($i = 0; $i <= $count; $i++) {
            $month_s = strtotime("+" . $i . " month", $this->start);
            $arr["menu"][$i] = date("Ym", $month_s);
            $comm = array("between", array(strtotime(date("Y-m-1", $month_s)), strtotime(date("Y-m-t", $month_s))));
            if ($i == 0) {
                $arr[$i][$this->field] = array("between", array($this->start, $s_month_last));
            } else {
                $arr[$i][$this->field] = $i == $count ? array("between", array($e_month_first, $this->end)) : $comm;
            }
        }
        return $arr;
    }
}
